<include file="Inc/header" />
<script type="text/javascript" src="__PUBLIC__/scripts/sisyphus.min.js"></script>

        <style>

            .edit_item_txt{display:none;}
            .select{ box-shadow:none}
            input{ border:none; width:100px; color:#666;}
            .table_box input{ border:none; width:100px; color:#666;

                -webkit-transition: border-color ease-in-out .2s, box-shadow ease-in-out .2s;
                transition: border-color ease-in-out .2s, box-shadow ease-in-out .2s
            }

            .table_box input:focus {
                border: 1px solid #66afe9 !important;
                background:#fff;
                outline: 0;
                -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
                box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6)
            }
            .table_box{ color:#666}
            .table_box td{ padding:8px; line-height:33px; border:1px solid #d7d7d7; background:none}
            .table_box tr:hover{ background:#f7f5ee !important;}
            .search_box{ border:1px solid #f8f8f8; background:none; border-radius:4px}

            .add1{ background:#04BBA5; color:#FFF; padding:5px 0; margin-bottom:10px;}
            .add1:hover{ border:none}
            .add2{ background:#04BBA5; color:#FF0; padding:5px 0; margin-bottom:10px;}
            .add2:hover{ border:none}
            .add_goods_type{ padding:5px 0}

            .beizhulb{}
            .beizhulb li{ width:10%; float:left; height:35px; line-height:30px; overflow:hidden;}
            .beizhulb label{ float:right; color:#666; padding:0 5px;}
            .beizhulb input{ float:left; color:#999; border:1px solid #fff;width:40px; padding:5px}
            .select{ color:#666 !important; border:1px solid #e9e9e9 !important;
                padding: 6px 12px;
                font-size: 12px;
                line-height: 1.428571429;

                vertical-align: middle;
                background-color: #fff;
                border: 1px solid #d7d7d7;
                border-radius: 3px;
                -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
                box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
                -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
                transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s
            }

            .select:focus {
                border: 1px solid #66afe9 !important;
                outline: 0;
                -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
                box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6)
            }

            .count{ padding:10px 0 20px}
            .input-groupR {
                position: relative;
                display: table;
                border-collapse: separate
            }
            .input-group-addon {
                display: table-cell;
                padding: 6px 12px;
                font-size: 14px;
                font-weight: 400;
                line-height: 1;
                text-align: center;
                background-color: #eee;
                border: 1px solid #ccc;
                border-radius: 3px;
                width: 1%;
                white-space: nowrap;
                vertical-align: middle;
                border-top-left-radius: 0;
                border-bottom-left-radius: 0;
                border-left: 0
            }
            .inputText {
                width: 100%;
                border-top-right-radius: 0;
                border-bottom-right-radius: 0;
                border: 1px solid #d7d7d7;
                border-radius: 3PX;
                height: 14PX;
                padding: 7px 0;
                line-height: 14PX;
                text-indent: 5px;
                font-size: 12px;
                display: inline-block
            }
            .inputText:hover{border: 1px solid #66afe9 !important;
                outline: 0;
                -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
                box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6)}

         .borderT{
             border: 0px;
         }
        </style>
<div class="content-box" id="tab1">
                            <form action="{:U('Admin/Kucun/update')}" method="post" name="search_form">
                            <input name="school_id" type="hidden" value="{$school_id}"/>
                            <input name="total_money" id='total_money' type="hidden" value=""/>
                            <table class="table_box" width="100%">
                                <tr style="background:#f8f8f8">
                                    <td width="10%" align="right">供货方：</td>
                                    <td><select name="sort" class="search_box select" style="height:33px; padding:4px 5px 5px; border:1px solid #e9e9e9">
                                            <volist name="company_array" id="class">
                                                <option value="{$class['main_sort']}">{$class['main_sort']}【{$class['name']}】</option>
                                            </volist>
                                        </select>
                                        </td>
                                    <td width="10%" align="right">入库日期：</td>
                                    <td><input class="search_box time_input select datepicker" name="date" holder="日期" style="width:97%" value="{$current_date}"/></td>
                                    <td width="10%" align="right">单据编号：</td>
                                    <td><input class="search_box time_input select" name="danjuhao" id="danjuhao" holder="单据编号" style="width:97%"  value="{$danjuhao}"/></td>
                                </tr>
                                <tr style="background:#f8f8f8">
                                    <td width="10%" align="right">收货人：</td>
                                    <td colspan="5"><input class="search_box time_input select" name="shouhuoren" holder="" style="width:97%" value="{$school_info.shouhuoren}"/></td>

                                </tr>
                            </table><br />

                            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_box" id="table2">
                                <tr>
                                    <td>序号</td>
                                    <td>名称</td>
                                    <td>单位</td>
                                    <td>单价</td>
                                    <td>数量</td>
                                    <td>总金额</td>
                                    <td>操作</td>
                                </tr>


                                <tr>
                                    <td class="listid">1</td>
                                    <td><input type="hidden" class="mid" name="detail[1][mid]" value=""/>
                                    <input type="hidden" class="cname" name="detail[1][mname]" value=""/>
                                    <input type="hidden" class="guige" name="detail[1][guige]" value=""/>
                                    <input type="hidden" class="guige_unit" name="detail[1][guige_unit]" value=""/>
                                        <input type="text" name="detail[1][name]" class="mname search_box select" style="width:200px;" holder="输入拼音首字母或条码,查询不到请先添加商品,添加一个商品是请删除此行"/>
                                        </td>
                                    <td><select name="detail[1][unit_type]" class="unit_select select search_box" holder="单位">
                                        <option value="斤">斤</option>
                                        <option value="个">个</option>
                                        <option value="袋">袋</option>
                                        <option value="桶">桶</option>
                                        <option value="包">包</option>
                                        <option value="箱">箱</option>
                                        <option value="件">件</option>
                                        <option value="瓶">瓶</option>
                                    </select></td>
                                    <td><input type="number" class="price select search_box" name="detail[1][price]"/></td>
                                    <td><input type="number" name="detail[1][number]" class="num search_box select"/></td>
                                    <td><input type="number" name="detail[1][zmoney]" class="zmoney search_box select"/></td>
                                    <td><button class="shanchu button">删除</button></td>
                                    <input type="button" name="add1" class="add1 button1" value="增加行"/>
                                </tr>

                            </table>
                            <div class="count">
                                <table width="300" cellspacing="0" cellpadding="5" border="0" align="right">

                                    <tr>
                                        <td class="borderT"><span style=" font-size:14px; color:#666">总计金额：</span></td>
                                        <td class="borderT" align="right"><span style=" font-size:16px; color:#f00">￥<span id="znum">0.00</span></span></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" class="borderT" ><select name="memo" class="search_box select" style="height:33px; padding:4px 5px 5px; border:1px solid #e9e9e9">
                                            <option value="购回" selected="selected">购回</option>
                                            <option value="上期结转">上期结转</option>
                                        </select>
                                        </td>
                                    </tr>
                                    </tbody></table>
                                <div style="clear:both"></div>
                            </div>
                            <div style="clear:both"></div>
                            <div style="width:100%;background:#f8f8f8; border:1px solid #d7d7d7;display:block; padding:10px 0 0" >
                                 <div style="clear:both; padding:10px 10px 0; background:#fff;">
                                 <div style="float:right">
                                        <!--input value="重置" class="button1" onclick="location.reload()" /-->
                                        <input type="button" value="保存" id="rukuing" class="button1" />
                                    </div>
                                    <div style="clear:both"></div>
                                </div>
                                <div style="clear:both"></div>
                            </div>
                            </form>
                            <div class="blank"></div>
 </div>

<script>
    $( function() {
        $( "#tab1" ).sisyphus();
    } );
</script>
<script>

    jQuery(function($){

        //添加行

        var fieldCount = 1;

        $(".add1").live("click",(function(){

            fieldCount++;

            $("#table2>tbody").append('<tr><td class=\"listid\">'+fieldCount+'</td>' +
                '<td><input type=\"hidden\" class=\"mid\" name=\"detail['+fieldCount+'][mid]\" value=\"\"/>' +
                '<input type=\"hidden\" class=\"cname\" name=\"detail['+fieldCount+'][mname]\" value=\"\"/>' +
                '<input type=\"hidden\" class=\"guige\" name=\"detail['+fieldCount+'][guige]\" value=\"\"/>' +
                '<input type=\"hidden\" class=\"guige_unit\" name=\"detail['+fieldCount+'][guige_unit]\" value=\"\"/>' +
                '<input type=\"text\" name=\"detail['+fieldCount+'][name]\" class=\"mname search_box select\" style=\"width:200px;\"/>' +
                '</td>' +
                '<td><select name=\"detail['+fieldCount+'][unit_type]\" class=\"unit_select select search_box\" holder=\"单位\">' +
                '<option value=\"斤\">斤</option><option value=\"斤\">斤</option><option value=\"袋\">袋</option><option value=\"桶\">桶</option>' +
                '<option value=\"包\">包</option>' +
                '<option value=\"瓶\">瓶</option>' +
                '</select></td>' +
                '<td><input type=\"number\" class=\"price select search_box\" name=\"detail['+fieldCount+'][price]\"/></td>' +
                '<td><input type=\"number\" name=\"detail['+fieldCount+'][number]\" class=\"num select search_box\"/></td>' +
                '<td><input type=\"number\" name=\"detail['+fieldCount+'][zmoney]\" class=\"zmoney search_box select\"/></td>' +
                '<td><button class=\"button\" onclick="deltr(this)">删除</button></td></tr>')

        }));

        var subfieldCount = 0;

        $(".add2").live("click",(function(){

            subfieldCount++;
            var $sku_html = $("#sku_html").html();
            var $list_id=$(this).parent().parent().find(".listid").html();  //规格
            var $mid=$(this).parent().parent().find(".mid").val();  //规格
            re = new RegExp("{list}","g"); //定义正则表达式
            re2 = new RegExp("{slist}","g"); //定义正则表达式
            $sku_html=$sku_html.replace(re,$list_id);
            $sku_html=$sku_html.replace(re2,subfieldCount);
            $sku_html=$sku_html.replace('{mid}',$mid);
            // $sku_html=$sku_html.replace('{td}','</td><td>');
            var $start_s = '<tr><td></td><td></td><td></td><td colspan=\"6\">';
            var $end_s = '</td></tr>';
            $sku_html=$start_s+$sku_html+$end_s;
            $("#table2>tbody").append($sku_html);
            //  $("#table2>tbody").append('<tr><td>'+subfieldCount+'</td><td><input type=\"hidden\" class=\"mid\" name=\"detail['+fieldCount+'][mid]\" value=\"\"/><input type=\"hidden\" class=\"cate_id\" name=\"detail['+fieldCount+'][cate_id]\" value=\"\"/><input type=\"hidden\" class=\"unit\" name=\"detail['+fieldCount+'][unit]\" value=\"\"/><input type=\"hidden\" class=\"funit\" name=\"detail['+fieldCount+'][funit]\" value=\"\"/><input type=\"hidden\" class=\"times\" name=\"detail['+fieldCount+'][times]\" value=\"\"/><input type=\"hidden\" class=\"yuan_price\" name=\"detail['+fieldCount+'][yuan_price]\" value=\"\"/><input type=\"text\" name=\"detail['+fieldCount+'][name]\" class=\"mname search_box\" style=\"width:200px;\"/><input type=\"hidden\" name=\"detail['+fieldCount+'][barcode]\" class=\"barcode\"/></td><td><select name=\"detail['+fieldCount+'][type]\" class=\"type_select select search_box\" holder=\"类型\">   <option value=\"0\">出售商品</option> <option value=\"1\">消耗品</option><option value=\"2\">顾客存</option></select></td><td><select name=\"detail['+fieldCount+'][unit_type]\" class=\"unit_select  select search_box\" holder=\"单位\"><span class=\"unit_select\"></span></select></td><td><input type=\"text\" class=\"price select search_box\" name=\"detail['+fieldCount+'][price]\"/></td><td><input type=\"text\" name=\"detail['+fieldCount+'][num]\" class=\"num select search_box\"/></td><td><input type=\"text\" name=\"detail['+fieldCount+'][zmoney]\" class=\"zmoney search_box\"/></td><td><input type=\"text\" name=\"detail['+fieldCount+'][memo]\" class=\"select search_box\"/></td><td><button onclick="deltr(this)">删除</button></td></tr>')

        }));

        $(".shanchu").live("click",(function(){
            $(this).parents("tr").remove();
        }));


    });

    //删除行的函数，必须要放domready函数外面

    function deltr(delbtn){

        $(delbtn).parents("tr").remove();

    };


    jQuery(function($){

        //定义删除按钮事件绑定

        //写里边，防止污染全局命名空间

        function deltr(){

            $(this).parents("tr").remove();

        };
        //已有删除按钮初始化绑定删除事件


        //计算总金额函数
        function total_money() {
            var money=0;
            $(".zmoney").each(function(){
                var zmoney=$(this).val();
                zmoney = zmoney * 10;
                money+=parseInt(zmoney);
            });
            //  alert(money);
            money = (money / 10).toFixed(1);
            $("#znum").html(money); //总金额自动填入
            $("#total_money").val(money); //总金额自动填入
        }


        $("#table2 .del").click(deltr);


        function accMul(arg1,arg2){
            var m=0,s1=arg1.toString(),s2=arg2.toString();
            try{m+=s1.split(".")[1].length}catch(e){}
            try{m+=s2.split(".")[1].length}catch(e){}
            return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
        }

        $('.num').live("blur",(function() {

            var num = ($(this).val());

            var price = $(this).parent().parent().find(".price").val();  //价格

            /* //zongjine=num*price; */
            zongjine = accMul(num, price);
            zongjine=zongjine.toFixed(1);
            $(this).parent().parent().find(".zmoney").val(zongjine); //总金额自动填入
            total_money();
        }));
        $('.price').live("blur",(function() {

            var price = ($(this).val()); //价格

            var num = $(this).parent().parent().find(".num").val();  //数量

            if(parseInt(num)>0){
                /* //zongjine=num*price; */
                zongjine = accMul(num, price);
                zongjine=zongjine.toFixed(1);
                $(this).parent().parent().find(".zmoney").val(zongjine); //总金额自动填入
                total_money();
            }
        }));

        $('.zmoney').live("blur",(function() {
            total_money();
        }));

        $("#rukuing").live("click",(function(){
            if($("#danjuhao").val()=='' || $("#total_money").val()=='' ){
                alert("请输入单据号或是没有任何物品，禁止空入库");
            }else{
                document.search_form.submit();
            }
        }));

    });

</script>

<script type="text/javascript">
    var data = {$autodata};
    $().ready(function(){
        $(".mname").live("focus",function(){
            $(this).autocomplete(data,
                {

                    delay:2,//延迟10秒

                    max:15,//最多5条记录

                    minChars:1,

                    matchSubset:1,

                    matchContains:1,

                    cacheLength:10,

                    matchContains: true,

                    scrollHeight: 220,

                    width:200,

                    mustMatch:false,

                    multiple: false,

                    autoFill: false,				//是否选多个,用","分开

                    formatItem: function(item) {
                        return item.name+item.pinyin;
                    }
                }).result(function(event,item) {

            });
            $(".mname").result(function(event, item) {				//额外触发,可不要
                $(this).parent().parent().find(".cname").val(item.name);
                $(this).parent().parent().find(".mid").val(item.id);
                $(this).parent().parent().find(".guige").val(item.guige);
                $(this).parent().parent().find(".guige_unit").val(item.guige_unit);
                $(this).parent().parent().find(".unit_select").val(item.unit);

            });
        });
    });
</script>

<include file="Inc/footer" />